package com.example.shiro.controller;

import com.example.shiro.comm.MinioUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

@RestController
public class IndexController {
    @Autowired
    private MinioUtil minioUtil;
    @Autowired
    RabbitTemplate rabbitTemplate;

    @RequestMapping("/")
    @RequiresPermissions("index:select")
    public String index(){
        return "index";
    }

    @RequestMapping("/update")
    @RequiresPermissions("index:update")
    public String update(){
        return "update";
    }

    @RequestMapping("/add")
    @RequiresPermissions("index:delete")
    public String add(){
        return "add";
    }

    @RequestMapping("/page403")
    @RequiresPermissions("index:delete")
    public String page403(){
        return "{code:403}";
    }

    @RequestMapping("/send/{msg}")
    public String send(@PathVariable String msg){
        long bengin = System.currentTimeMillis();
        for(int i = 0; i <= 1000; i++) {
            rabbitTemplate.convertAndSend("TestDirectExchange", "TestDirectRouting", msg+i);
        }
        System.out.println(System.currentTimeMillis()-bengin);
        return msg;
    }
    @RequestMapping("/minio")
    public Boolean minio(){
        return minioUtil.putObject("itstyle", UUID.randomUUID().toString(),"D:/file/1.txt");
    }
    @RequestMapping("/geturl")
    public String getUrl(){
        return minioUtil.presignedGetObject("itstyle","001.jpg",60);
    }
}
